"""
CheckListBox
============

A `CheckListBox` is just like a `ListBox`, except that it gives you methods and
an event to handle toggling of its items.
"""
from wxpita import *

animals = ['bear', 'hare', 'duck', 'boar', 'lion', 'vole', 'goat']


f = SizedFrame [
    CheckListBox(name='chklst1', choices=animals, expand=1, proportion=1),

    CheckListBox(name='chklst2', expand=1, proportion=1),

    TextCtrl(name='log', style='te_multiline', expand=1, proportion=1),
]

@f.Init
def _():
    for i in (1, 3, 5, 6):
        f.chklst1.Check(i, True)
    
    for i in range(25105, 25315, 10):
        f.chklst2.Append(''.join(unichr(j) for j in range(i,i+5)))

@f.chklst1.checklistbox_toggled
@f.chklst2.checklistbox_toggled
def _(evt):
    chklst = evt.EventObject
    i = evt.Selection
    
    f.log.AppendText('You %schecked <%s> in <%s>\n' % (
        '' if chklst.IsChecked(i) else 'un', 
        chklst.GetString(i),
        evt.EventObject.GetName()))

f.Show('CheckListBox Example', size=(350,500))
